package dp;

import java.util.ArrayList;
import java.util.List;

public class generate {
    public List<List<Integer>> generate(int numRows) {
        //初始化数组
        int[][]dp= new int[numRows][numRows];
        for(int i=0;i<numRows;i++){
            dp[0][i]=1;
            dp[i][0]=1;
        }
        //1 1 1 1 1
        //1 2 3 4 
        //1 3 6 
        //1 4 
        //1 
        List<List<Integer>> list = new ArrayList<>();
        for(int i=1;i<numRows-1;i++){
            //对角线遍历
            for(int j=1;j<numRows-i;j++){
                dp[i][j]=dp[i][j-1]+dp[i-1][j];
            }
        }
        //添加list
        for(int i=0;i<numRows;i++){
            ArrayList<Integer> sublist = new ArrayList<>();
            int row=i,col=0;
            for(int j=0;j<=i;j++){
                //处理的元素个数
                
                sublist.add(dp[row][col]);
                row--;
                col++;
            }
            list.add(sublist);
        }
        return list;
    }
    public static void main(String[] args) {
        generate obj = new generate();
        List<List<Integer>> list = obj.generate(5);
        for(List<Integer> subList:list){
            for(Integer i:subList){
                System.out.println(i);
            }
            System.out.println("============");
        }
    }
}
